home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / SAT 2.1.2 / Collision][ ƒ / sApple][.p < prev    next >
Encoding:
Text File  |  1994-06-02  |  2.2 KB  |  100 lines  |  [TEXT/PJMM]

  1. { Apple sprite for SATcollision][ }
  2. { No, it has nothing to do with old Apple computers :-) }
  3.  
  4. unit sApple;
  5.  
  6. interface
  7.  
  8.     uses
  9.         SAT;
  10.  
  11.     var
  12.         nammSound, bliaehSound: Handle;
  13.         goodFace, badFace: FacePtr;
  14.         coreDump: FacePtr;
  15.  
  16.     procedure InitApple;
  17.     procedure SetupApple (me: SpritePtr);
  18.     procedure HandleApple (me: SpritePtr);
  19.     procedure HitApple (me, him: SpritePtr);
  20.  
  21. implementation
  22.  
  23.     procedure InitApple;
  24.         var
  25.             i: integer;
  26.     begin
  27.         nammSound := SATGetNamedSound('namm');
  28.         bliaehSound := SATGetNamedSound('bliaeh');
  29.         goodFace := GetFace(132);
  30.         badFace := GetFace(133);
  31.         coreDump := GetFace(135);
  32.     end;
  33.  
  34.     procedure SetupApple (me: SpritePtr);
  35.     begin
  36.         me^.speed.h := 1 + Rand(3);
  37.         me^.kind := -2; {Enemy kind}
  38.         me^.face := GoodFace;
  39.         SetRect(me^.hotRect, 0, 0, 32, 32);
  40.         me^.task := @HandleApple;
  41.         me^.hitTask := @HitApple;
  42.     end;
  43.  
  44. {We use kind -2 for fresh apples and kind -3 for bad apples. We avoid -1, since it doesn't count for the "anymonsters" flag.}
  45. {Note that the "kind" field is not modified my SAT since we are not using KindCollision!}
  46.  
  47.     procedure HandleApple (me: SpritePtr);
  48.     begin
  49.  
  50.         case me^.kind of
  51.             -2: 
  52.                 me^.face := goodFace;
  53.             -3: 
  54.                 me^.face := badFace;
  55.         end;
  56.  
  57.         me^.position.h := me^.position.h + me^.speed.h;
  58.         if me^.position.h > gSAT.offSizeH - 16 then
  59.             begin
  60.                 me^.speed.h := -1 - Rand(3);
  61.                 if Rand(2) = 0 then
  62.                     me^.kind := -3
  63.                 else
  64.                     me^.kind := -2;
  65.             end;
  66.         if me^.position.h < -16 then
  67.             begin
  68.                 me^.speed.h := 1 + Rand(3);
  69.                 if Rand(2) = 0 then
  70.                     me^.kind := -3
  71.                 else
  72.                     me^.kind := -2;
  73.             end;
  74.     end;
  75.  
  76.     procedure HitApple;
  77.     begin
  78.         if him^.task = @HandleApple then
  79.             me^.kind := -3 {Colliding apples corrupt each other!}
  80.         else
  81. {If "him" is not an apple, then it must be the player!}
  82.             if him^.mode >= 0 then {if the player feels bad, don't eat}
  83.                 case me^.kind of
  84.                     -2: 
  85.                         begin
  86.                             SATSoundPlay(nammSound, 1, false);
  87.                             me^.task := nil;
  88.                             him^.mode := 25;
  89.                             SATPlotFace(coreDump, nil, nil, me^.position, true);
  90.                         end;
  91.                     -3: {Bad apple, make player feel bad.}
  92.                         begin
  93.                             him^.mode := -20;
  94.                             SATSoundPlay(bliaehSound, 2, false);
  95.                         end;
  96.                     otherwise {This shouldn't happend!}
  97.                 end;
  98.     end;
  99.  
  100. end.